<template>
  <el-main>
    <!-- 搜索框 -->
    <el-form
      ref="searchForm"
      :model="parms"
      label-width="80px"
      :inline="true"
      size="small"
    >
      <el-form-item label="标题">
        <el-input v-model="parms.title" />
      </el-form-item>
      <el-form-item label="内容">
        <el-input v-model="parms.complaintContent" />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="searchBtn">查询</el-button>
        <el-button
          style="color: #ff7670"
          icon="el-icon-close"
          @click="resetBtn"
        >重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table :height="tableHeight" :data="tableList" border stripe>
      <el-table-column label="标题" prop="title" />
      <el-table-column label="内容" prop="complaintContent" />
      <el-table-column label="处理状态" prop="status">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == '1'" type="success" size="small">已处理</el-tag>
          <el-tag v-if="scope.row.status == '0'" type="danger" size="small">未处理</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="120">
        <template slot-scope="scope">
          <el-button
            v-if="hasPerm('sys:userComplaintList:do')"
            type="success"
            icon="el-icon-delete"
            size="small"
            @click="doBtn(scope.row)"
          >处理</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      :current-page.sync="parms.currentPage"
      :page-sizes="[10,20, 40, 80, 100]"
      :page-size="parms.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="parms.total"
      background
      @size-change="sizeChange"
      @current-change="currentChange"
    />
  </el-main>
</template>

<script>
import { getListApi, editApi } from '@/api/userComplaint'
export default {
  data() {
    return {
      // 新增投诉绑定对象
      addModel: {
        complaintId: '',
        userId: '',
        editType: '',
        title: '',
        complaintContent: ''
      },
      // 定义弹框属性
      addDialog: {
        title: '',
        height: 180,
        width: 650,
        visible: false
      },
      // 表格高度
      tableHeight: 0,
      // 表格数据
      tableList: [],
      // 列表查询参数
      parms: {
        currentPage: 1,
        pageSize: 10,
        title: '',
        complaintContent: '',
        total: 0
      }
    }
  },
  created() {
    this.getList()
  },
  mounted() {
    this.$nextTick(() => {
      this.tableHeight = window.innerHeight - 210
    })
  },
  methods: {
    // 处理按钮
    async doBtn(row) {
      if (row.status === '1') {
        this.$message.warning('该投诉已经处理，无需重复处理！')
        return
      }
      const parm = {
        complaintId: row.complaintId,
        status: '1'
      }
      const confirm = await this.$myconfirm('确定处理该投诉吗?')
      if (confirm) {
        const res = await editApi(parm)
        if (res && res.code) {
          // 刷新表格
          this.getList()
          this.$message.success(res.msg)
        }
      }
    },
    // 页数改变时触发
    currentChange(val) {
      this.parms.currentPage = val
      this.getList()
    },
    // 页容量改变时触发
    sizeChange(val) {
      this.parms.pageSize = val
      this.getList()
    },
    // 重置按钮
    resetBtn() {
      // 清除搜索框的数据
      this.parms.complaintContent = ''
      this.parms.title = ''
      this.getList()
    },
    // 查询按钮
    searchBtn() {
      this.getList()
    },
    // 获取投诉列表
    async getList() {
      const res = await getListApi(this.parms)
      console.log(res)
      if (res && res.code === 200) {
        // 把返回的数据放到表格
        this.tableList = res.extend.list.records
        this.parms.total = res.extend.list.total
      }
    }
  }

}
</script>

<style lang="scss" scoped>

</style>
